package com.suntront.module_datasynch.taskup

import android.view.View
import android.widget.Button
import com.alibaba.android.arouter.facade.annotation.Route
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.mtjsoft.www.kotlinmvputils.base.BaseRecycleViewModel
import com.mtjsoft.www.kotlinmvputils.base.BaseRecycleviewActivity
import com.mtjsoft.www.kotlinmvputils.constants.RouterConstants
import com.suntront.lib_db.table.MeterT
import com.suntront.module_datasynch.R
import com.suntront.module_datasynch.adapter.TaskUpAdapter

/**
 * 上传抄表任务
 * @author mtj
 * @Package com.suntront.module_datasynch.taskup
 * @date 2020-05-27 10:16:07
 */
@Route(path = RouterConstants.DataAsynch_UP)
class TaskUpRecycleViewActivity : BaseRecycleviewActivity<MeterT, TaskUpViewModel>() {

    override fun providerVMClass(): Class<TaskUpViewModel>? {
        return TaskUpViewModel::class.java
    }

    override fun loadActivityInfo() {
        setPageTitle("上传任务")
        viewModel.refresh.value = false
        viewModel.load_more.value = false
        // 添加立即上传按钮
        val downView = View.inflate(getContext(), R.layout.include_download_btu, null)
        val btndownload = downView.findViewById<Button>(R.id.btu_download)
        btndownload.setOnClickListener(this)
        btndownload.text = "立即上传"
        getBaseBottomLayout().addView(downView)
    }

    override fun setItemDecoration(): Int {
        return 0
    }

    override fun setPageSize(): Int {
        return Int.MAX_VALUE
    }

    override fun setLayoutManagerType(): BaseRecycleViewModel.LayoutManager {
        return BaseRecycleViewModel.LayoutManager.LinearLayoutManager
    }

    override fun setCount(): Int {
        return 2
    }

    override fun instanceAdapter(list: MutableList<MeterT>): BaseQuickAdapter<MeterT, BaseViewHolder> {
        return TaskUpAdapter(getContext(), list)
    }

    override fun onClick(p0: View) {
        super.onClick(p0)
        when (p0.id) {
            R.id.btu_download -> {
                viewModel.update()
            }
        }
    }
}